#include <stdio.h>
#include <string.h>
#include <unistd.h>

int main()
{
  char buf[100];
  int pipefd[2]={0};

  pipe(pipefd);

  //read stdin
  while(fgets(buf,100,stdin)){
    int len = strlen(buf);
    //write to pipe 
    if(write(pipefd[1],buf,len) != len){
      perror("write error\n");
      break;
    }
    memset(buf,0,sizeof(buf));

    //read pipe 
    if((len = read(pipefd[0],buf,100)) == -1){
      perror("read pipe ");
      break; 
    }

    //write to stdout
    if(write(1,buf,len) != len){
      perror("write error\n");
      break; 
    }
  }
  return 0;
}
